package com.phantasy.scene.sceneUnit.map
{
	import com.phantasy.loaders.ResourcePool;
	import com.phantasy.loaders.gameLoader.GameLoader;
	import com.phantasy.loaders.gameLoader.ResourceItem;
	import com.phantasy.modules.scene.SceneDataManager;
	import com.phantasy.scene.WorldManager;
	import com.phantasy.scene.sceneData.CityVo;
	import com.phantasy.scene.sceneData.MapDataVo;
	
	import flash.display.Sprite;
	
	public class Map extends Sprite
	{
		public static var isCanLoadedMap:Boolean = true;
		
		private var _inited:Boolean;
		private var bgLayer:MapBackGround;
		private var activeLayer:Sprite;
		private var smallURL:String;
		private var lastX:int=0;
		private var lastY:int=0;
		
		public function Map()
		{
			super();
			this.init();
		}
		
		private function init():void
		{
			if(this._inited==false){
				this.mouseEnabled=false;
				bgLayer = new MapBackGround();
				this.addChild(this.bgLayer);
				activeLayer = new Sprite();
				activeLayer.mouseEnabled=false;
				this.addChild(this.activeLayer);
				this._inited=true;
			}		
		}
		
		public function reset():void
		{
			var mapDataVo:MapDataVo = SceneDataManager.mapData;
			this.bgLayer.startInitMap(mapDataVo.map_id, mapDataVo.width, mapDataVo.height);
		}
		
		/**
		 *开始加载模糊下小地图 
		 * 
		 */		
		public function startLoadBlur():void
		{
			var mapID:int = SceneDataManager.mapID;
			var cityVo:CityVo = WorldManager.getCityVo(mapID);
			this.smallURL = (("com/maps/smallMap/" + cityVo.url.substring(16, cityVo.url.length)) + ".swf");
			if (ResourcePool.hasResource(this.smallURL) == false)
			{
				GameLoader.getInstance().add(this.smallURL, ResourceItem.PRIORITY_1, true, null, this.onSmallMapSwfComplete);
			}
			else
			{
				this.onSmallMapSwfComplete();
			}
		}
		
		public function loadPiece():void
		{
			if (!(this.x == this.lastX) || !(this.y == this.lastY) && (isCanLoadedMap == true))
			{
				this.lastX = this.x;
				this.lastY = this.y;
				this.bgLayer.loadMap(this.x, this.y);
			}
		}
		
		private function onSmallMapSwfComplete(data:Object=null):void
		{
			
		}
		
		public function clear():void
		{
			
		}
	}
}